package com.immac.chan.util;

import java.util.ArrayList;

public class LeeJCStringUtil {
	public static String readLine() throws Exception {
		int input = System.in.read();
		String str = "";

		while (input != '\n') {
			if (input != '\r') {
				str += (char)input;
			}
			input = System.in.read();
		}

		return str;
	}

	public static String[] split(String str, char regex) {
		ArrayList<String> strList = new ArrayList<String>();
		String temp = "";
		int index = 0;
		
		while (index < str.length()) {
			char ch = charAt(str, index++);
			if (ch != regex) {
				temp += ch;
			} else {
				strList.add(temp.trim());
				temp = "";
			}
		}
		strList.add(temp.trim());
		
		String[] strs = new String[strList.size()];
		
		for (int i = 0; i < strs.length; i++) {
			strs[i] = strList.get(i);
		}
		
		return strs;
	}
	
	public static char charAt(String str, int index) {
		char[] chars = str.toCharArray();
		
		return chars[index];
	}
	
	public static int indexOf(String str, char ch) {
		char[] chars = str.toCharArray();
		int index = 0;
		
		while (index < str.length()) {
			if (chars[index++] == ch) {
				break;
			}
		}
		
		return index - 1; 
	}
}
